﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESPL.CodeGenerator.Common.ProjectBuilders;
using ESPL.CodeGenerator.Common.Structs;
using ESPL.CodeGenerator.Common;
using ESPL.CodeGenerator.Domain.TemplateGenerators.CSharpCodeGenerators;
using ESPL.CodeGenerator.Domain.TemplateGenerators.SolutionGenerators;
using ESPL.CodeGenerator.Domain.Utilities;
using System.IO;

namespace ESPL.CodeGenerator.Domain.ProjectBuilders
{
    internal class SolutionBuilder : CodeBuilderBase, ISolutionBuilder
    {
        #region Declarations

        private IList<IProjectBuilder> _projects = new List<IProjectBuilder>();

        #endregion

        #region Constructor

        public SolutionBuilder(ApplicationConfiguration config) : base(config)
        {
            CreateDir = true;
            WriteFile = true;
        }

        #endregion

        #region Methods

        protected override string GetDirectoryPath()
        {
            return FileHelper.CombinePath(Config.DestinationPath, Config.ApplicationName);
        }

        protected override string GetFilePath()
        {
            return FileHelper.CombinePath(GetDirectoryPath(), string.Format("{0}.{1}.sln", Config.CompanyNameAbbrevation, Config.ApplicationName));
        }

        protected override void InitGenerator()
        {
            switch (Config.VisualStudioVersion)
            {
                case ESPL.CodeGenerator.Common.Enums.VisualStudioVersion.None:
                    break;
                case ESPL.CodeGenerator.Common.Enums.VisualStudioVersion.VS2010:
                    _generator = new SolutionGenerator2010(Config, _projects);
                    break;
                case ESPL.CodeGenerator.Common.Enums.VisualStudioVersion.VS2013:
                    _generator = new SolutionGenerator2013(Config, _projects);
                    break;
                case ESPL.CodeGenerator.Common.Enums.VisualStudioVersion.VS2015:
                    _generator = new SolutionGenerator2015(Config, _projects);
                    break;
            }
        }

        protected override BuilderResponse GetResponse()
        {
            return new BuilderResponse { Output = string.Format("{0} Solution Created at: {1}", _generator.ToString(), GetFilePath()) };
        }

        public void AddProject(IProjectBuilder projectBuilder)
        {
            _projects.Add(projectBuilder);
        }

        #endregion
    }
}
